#include "../Project/MyLog.h"
using namespace MyLog;

void test1(const std::string &name)
{
    DEBUG("%s","测试日志开始");
    Logger::ptr s=LoggerManager::GetInstance().GetLogger(name);
    
    s->info("%s","测试日志");
    s->debug("%s","测试日志");

    s->error("%s","测试日志");
    s->fatal("%s","测试日志");
    s->warning("%s","测试日志");

    std::size_t cur=Common::Date::GetNowTimeStamp();
    std::size_t count=0;
    while(Common::Date::GetNowTimeStamp()<cur+5)
    {
        s->fatal("测试日志count-%d",count++);
        // sleep(1);
        // if(count>5e5)break;
    }
    INFO("%s","测试日志结束");
}
void test2()
{
    std::string loggername="async-test";
    const LogLevel::Level limit=LogLevel::Level::DEBUG;

    std::unique_ptr<LoggerBuilder> builder(new GlobalLoggerBuilder());
    builder->buildLoggerName(loggername);
    builder->buildLogLevel(limit);
    builder->buildFormatter(PATTERN);
    builder->buildLogType(LoggerType::LOGGER_ASYNC);

    builder->buildLogSink<RollSinkByTimeGap>("./TestLog/roll-async-time.log",TimeGap::GAP_SECOND);
    builder->build();
    test1(loggername);
}
void test4(const std::string &name)
{
    DEBUG("%s","测试日志开始");
    Logger::ptr s=LoggerManager::GetInstance().GetLogger(name);
    s->info("%s","测试日志");
    s->debug("%s","测试日志");

    s->error("%s","测试日志");
    s->fatal("%s","测试日志");
    s->warning("%s","测试日志");

    // std::size_t cur_size=0,count=0;
    // while(count < 5e5)
    // {
    //     s->fatal("测试日志count-%d",count++);
    //     cur_size+=20;
    // }
    INFO("%s","测试日志结束");
}
void test3()
{
    std::string loggername="sync-test";
    const LogLevel::Level limit=LogLevel::Level::DEBUG;

    std::unique_ptr<LoggerBuilder> builder(new GlobalLoggerBuilder());
    builder->buildLoggerName(loggername);
    builder->buildLogLevel(limit);
    builder->buildFormatter(PATTERN);
    builder->buildLogType(LoggerType::LOGGER_SYNC);
    // builder->buildEnableUnsafe();
    builder->buildLogSink<StdOutSink>();
    builder->buildLogSink<FileSink>("./TestLog/test.log");
    builder->buildLogSink<RollSinkBySize>("./TestLog/roll-sync-size.log",1024*1024);
    builder->build();

    test4(loggername);
}

int main()
{
    // test3();
    // sleep(5);
    test2();// 得分开测试，一起测试会有问题
    return 0;
}

